<?php
	class Payment extends CI_Controller{
		function __construct(){
			parent::__construct();	
		}
		public function index(){
			echo "test";
		}
		function paypal() {
			$tigia = 20000;
			$id = $this->input->get("order",true);
			if(!empty($id)){
				$this->load->helper(array("string","url"));
				$config['business']  = 'dhdongthap@gmail.com';
				$config['cpp_header_image']  = ''; 
				$config['return']  = base_url().'default/payment/notify_payment?pay='.$id;
				$config['cancel_return']  = base_url().'default/payment/cancel_payment?pay='.$id;
				$config['notify_url']  = 'process_payment.php'; 
				$config['production']  = false; 
				$config["invoice"]= random_string('numeric', 8); 
				$this->load->library('paypal',$config);
				$this->load->model('Orders_Model');
				$order=$this->Orders_Model->getOrderPaypal($id);
				//var_dump($order);die;
				$money = round($order->TotalPrice/$tigia,2);
				//echo $money; die;
				$this->paypal->add('TV Package '.$order->NameService_en." ".$order->Duration." month" , $money,1); //First item
				//$this->paypal->add('Quantay', 1.897, 3);  //Second item
				//$this->paypal->add('Aoso mi', 2, 1, 'ASM-001'); //Third item with code
				$this->paypal->pay(); //Proccessthe payment
			}
			else redirect();
		}
		function notify_payment() {
			/*echo '<pre>';
			print_r($_POST);
			echo '</pre>';*/
			$id = $this->input->get("pay",true);
			$this->load->model("Payments_Model");
			$payment = $this->Payments_Model->insertPayment();
			$this->load->model("Orders_Model");
			$this->Orders_Model->updateOrderPay($id,$payment);
			redirect("default/service/viewinvoice?id=".$id);
		}
		function cancel_payment() {
			$id = $this->input->get("pay",true);
			//echo $id;die;
			redirect("default/service/viewinvoice?id=".$id);
		}
		
	}
?>